package com.bytic.miaosha.rabbitmq;

import com.bytic.miaosha.constant.MQConstant;
import com.bytic.miaosha.domain.MiaoshaMessage;
import com.bytic.miaosha.utils.JsonUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class MQSender {

    private static Logger log = LoggerFactory.getLogger(MQSender.class);

    @Autowired
    private AmqpTemplate amqpTemplate;

    public void sendMiaoshaMessage(MiaoshaMessage message) {
        String s = JsonUtils.beanToString(message);
        log.info("send message: " + s);
        amqpTemplate.convertAndSend(MQConstant.MIAOSHA_QUEUE, s);
    }
}
